/**
 * Created by charsen on 16/6/14.
 */
directives.directive('addMonitor', ["$rootScope", "tools", "$timeout", function ($rootScope, tools, $timeout) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attr) {
            //$('.ui.dropdown').dropdown();
            scope.config = {};
            scope.msg = null;
            //scope.config.index = 1;
            $rootScope.$on('ADD_MONITOR_EV', function (e, config) {
//                console.log(e);
                //scope.config = {};
                /*scope.config = {
                 index: index123,
                 title:'111',
                 model: '',
                 keywords: ['', '', ''],
                 delkeywords: ['', ''],
                 price_low: '',
                 price_hig: '',
                 time: ""
                 };*/

                scope.config = config;

                console.log(scope.config);
                $timeout(function(){
                    $(element).modal('show');
                    $('.dropdown').dropdown({
                        onChange: function(value, text, $selectedItem) {
                            console.log("value:"+value+" text:"+text+"  $selectedItem:"+$selectedItem);
                            //console.log($selectedItem.attr('dataType'));
                            if($selectedItem.attr('dataType')==='价格设置'){
                                scope.config.priceSet = value;

                               // console.log(scope.config.priceSet);
                            }else if($selectedItem.attr('dataType')==='抓取频率设置'){
                                scope.config.timeSet = value;
                            }else if($selectedItem.attr('dataType')==='抓取时间设置'){
                                scope.config.dateSet = value;
                            }else{
                                return;
                            }
                            scope.$apply();
                        }
                    });
                },200);
            });

            /*scope.config = {
             model: '爽肤水 K00945',
             keywords: ['爽肤水', '清凉', '杭州专卖'],
             delkeywords: ['秋季', '婴儿'],
             price_low: '233',
             price_hig: '455',
             time: 5
             };*/
            //$('.openMonitor').checkbox();


            scope.ok = function(){
                if(scope.config.dateSet ==="自定义时间"){
                    scope.config.dateValue = $('#dateValue').val();
                }

                /*scope.config.model = $.trim(scope.config.model);
                if(scope.config.model==""){
                    scope.msg = '请输入产品型号';
                    $timeout(function(){
                        scope.msg = null;
                    },2000);
                    return;
                }
                if(scope.config.keywords[0]==""&&scope.config.keywords[1]==""&&scope.config.keywords[2]==""){
                    scope.msg = '请输入关键字';
                    $timeout(function(){
                        scope.msg = null;
                    },2000);
                    return;
                }
                if(tools.isNumberMath(scope.config.time)){
                    scope.msg = '请输入整数';
                    $timeout(function(){
                        scope.msg = null;
                    },2000);
                    return;
                }*/

                console.log(scope.config);
            };

        },
        templateUrl: "/trend-new-BI/app/components/priceMonitor/addMonitor/addMonitorView.html"
    }
}]);